package com.mail.server.controller;

import com.mail.model.dto.SmsCouponDto;
import com.mail.server.common.R;
import com.mail.server.service.SmsCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 优惠券表 前端控制器
 * </p>
 *
 * @author WJZ
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/coupon")
public class SmsCouponController {
    @Autowired
    private SmsCouponService service;

    @PostMapping("create")
    public R create(@RequestBody SmsCouponDto smsCouponDto) {
        return service.create(smsCouponDto);
    }

    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Long id) {
        return service.delete(id);
    }

    @GetMapping("list")
    public R list(@RequestParam(value = "name", required = false) String name
            , @RequestParam(value = "pageNum", required = false) Long pageNum
            , @RequestParam(value = "pageSize", required = false) Long pageSize
            , @RequestParam(value = "type", required = false) Integer type
    ) {
        return service.list(name, pageNum, pageSize, type);
    }

    @PostMapping("update/{id}")
    public R update(@PathVariable Long id, @RequestBody SmsCouponDto couponDto) {
        return service.update(id, couponDto);
    }
    @GetMapping("{id}")
    public R getCouponById(@PathVariable Long id){
        return service.getCouponById(id);
    }
}
